const del = require('del')
const path = require('path')

class ItsunCleanPlugin {
  constructor() {
    this.aplly = this.apply.bind(this)
  }

  apply(complier) {
    const hooks = complier.hooks
    hooks.emit.tap('itsun-clean-plugin', () => {
      try {
        const deleted = del.sync(['**/*'], {
          force: false,
          cwd: path.resolve(__dirname, '../../dist')
        })
      } catch (err) {
        console.error('itsun-clean-plugin删除文件错误')
        throw err
      }
    })
    hooks.done.tap('itsun-clean-plugin', () => {
      console.log('------------', 'itsun-clean-plugin done')
    })
  }
}
module.exports = ItsunCleanPlugin